<?php
// Modified from menu.php.

require_once('../../config.php');
require_once('security.php');

function html_escape ($string) {
	// usage: html_escape (string string)
	
	// Convience wrapper for htmlspecialchars().
	
	return htmlspecialchars ($string, ENT_COMPAT, "UTF-8");
}

  if (isset($_POST['submit'])) { // Handle the form

    $uri  = html_escape ($_POST['uri']);
    $text = html_escape (trim ($_POST['text']));
    
	$content = '<li><a href="' . $uri . '">' . $text . '</a></li>' . "\n";
	
    // Path to the .php file (to write the template)
    $filename = "../textfiles/favourites";

    // Write the contents
    $fp = fopen($filename, "a") or die("Couldn't open $filename.");
    fwrite($fp, $content);
    fclose($fp);

    // Feedback
    $response = "Added favourite.";
  }

?>

<?php $thisPage = "favourite"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Create a new navigation button</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">



<?php include_once('navigation.php'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Uniform Resource Identifier<br />
<input type="text" name="uri" id="uri" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['uri']; ?>" maxlength="60" />
<br />
Desired link text<br />
<input type="text" name="text" id="text" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['text']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Create favourite" />
</form>

<?php echo $response; ?>

<?php include_once('list-all.php'); ?>

<div style="clear: both;"></div>
</div>

</body>
</html>
